package com.chensf.studydemo.provider

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.StrictMode
import androidx.appcompat.app.AppCompatActivity
import com.chensf.studydemo.R
import kotlinx.android.synthetic.main.activity_provider_test.*
import java.io.File

class ProviderTestActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_provider_test)
        button1.setOnClickListener {
//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//                val builder = StrictMode.VmPolicy.Builder()
//                StrictMode.setVmPolicy(builder.build())
//            }

            var dir = filesDir
            var file = File(dir,"demo.docx")
            val contentUri = FileProvider7.getUriForFile(applicationContext, file)
            val intent = Intent(Intent.ACTION_VIEW)
            intent.addCategory(Intent.CATEGORY_DEFAULT)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            intent.setDataAndType(contentUri, "application/msword")
            startActivity(intent)
        }
    }
}